package com.chap11;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * <p>
 * <code>ThreadPoolTest</code>
 * </p>
 *
 * @author junbao3
 * TODO
 * @date 2023-04-03 15:22
 * Copyright (C) 2021 IFlyTek. All rights reserved.
 */
public class ThreadPoolTest2 {
    public static void main(String[] args) {
        ThreadPoolExecutor executor =
                new ThreadPoolExecutor(10, 200, 1000,
                        TimeUnit.SECONDS, new ArrayBlockingQueue<>(200), new ThreadFactory() {
                    @Override
                    public Thread newThread(Runnable r) {
                        Thread thread = new Thread(r);
                        thread.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
                            @Override
                            public void uncaughtException(Thread t, Throwable e) {
                                System.out.println("出错啦...");
                            }
                        });
                        return thread;
                    }
                });

        //往线程池提交任务
        executor.execute(new Runnable() {
            @Override
            public void run() {
                System.out.println("...");
                throw  new NullPointerException();
            }
        });
    }
}
